package com.example.mobile2121606109ycg0512;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class SupplierActivity extends AppCompatActivity {

    private RadioGroup radioGroup;
    private RadioButton radBtnSupplier1;
    private RadioButton radBtnSupplier2;
    private RadioButton radBtnSupplier3;
    private RadioButton radBtnSupplier4;
    private Button btnSupplierSubmit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_supplier);
        initView();

        btnSupplierSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int radBtnID=radioGroup.getCheckedRadioButtonId();
                if(radBtnID!=1){
                    RadioButton radBtn=findViewById(radBtnID);
                    Intent intent=new Intent();
                    intent.putExtra("supplier",radBtn.getText().toString());
                    setResult(RESULT_OK,intent);
                    finish();
                }else{
                    new AlertDialog.Builder(SupplierActivity.this)
                            .setMessage("请选择供应商")
                            .setPositiveButton("确定",null)
                            .create()
                            .show();
                }
            }
        });
    }

    private void initView() {
        radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
        radBtnSupplier1 = (RadioButton) findViewById(R.id.radBtnSupplier1);
        radBtnSupplier2 = (RadioButton) findViewById(R.id.radBtnSupplier2);
        radBtnSupplier3 = (RadioButton) findViewById(R.id.radBtnSupplier3);
        radBtnSupplier4 = (RadioButton) findViewById(R.id.radBtnSupplier4);
        btnSupplierSubmit = (Button) findViewById(R.id.btnSupplierSubmit);
    }
}